package com.etennis.controller;

import com.etennis.mapper.SeasonInfoMapper;
import com.etennis.pojos.ResponseResult;
import com.etennis.pojos.entity.Group;
import com.etennis.pojos.entity.Member;
import com.etennis.pojos.vo.app.UserVO;
import com.etennis.service.IGroupService;
import com.etennis.service.IMemberService;
import com.etennis.utils.BeanCopyUtils;
import com.etennis.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/rank")
@Slf4j
@Api(tags = "用户端-排行榜接口")
public class RankController {
    @Autowired
    private IGroupService groupService;
    @Autowired
    private SeasonInfoMapper seasonInfoMapper;
    @Autowired
    private IMemberService memberService;
    @GetMapping("/rank")
    @ApiOperation("根据组别展示排行榜")
    public ResponseResult<List<UserVO>> rank(@RequestParam("groupId") Long groupId){
        Member member= SecurityUtils.getLoginUser().getUser();
        List<Member> rankMember = seasonInfoMapper.getRankMember(groupId, member.getClubId());
        List<UserVO> userVOList = BeanCopyUtils.copyBeanList(rankMember, UserVO.class);
        return ResponseResult.okResult(userVOList);
    }
    @GetMapping("/getGroups")
    public ResponseResult<List<Group>> getGroups(){
        return ResponseResult.okResult(groupService.list());
    }


}
